<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php

class PerStatForm extends CMiniyunStatForm
{
	protected  function chartMethods(){
		return array("getPerHistogram");
	}
	
	private function getApiIds(){
		return array(
		'api.account.info',
		'api.fileops.copy',
		'api.fileops.create_folder',
		'api.fileops.delete',
		'api.fileops.move',
		'api.files_put',
		'api.medias',
		'api.metadata',
		'api.oauth.access_token',
		'api.oauth.authorize',
		'api.oauth.oauth',
		'api.oauth.request_token',
		'api.revisions',
		'api.search',
		'api.shares',
		'api.thumbnails'
);
	}
	
	private function getApiHistogramData($apiId){
		$space= 10;		$s = strtotime($this->startDate);
		$e = strtotime($this->endDate);
		$diff = (int)($e-$s)/(24*3600);
		if($diff>$space){
			$spaceValue = (int)$diff/$space;		}else{
			$spaceValue = 1;		}
		$x = array();
		for($item=$s; $item<=$e; $item+=$spaceValue*24*3600){
			array_push($x,date("Y-m-d",$item));
		}
		$data = array();		foreach($x as $index=>$currentDate){
			$data[$currentDate]=(int)($this->model->getPerformanceByApi($apiId,$currentDate));
		}
		return $data;
	}
	
	public function getPerHistogram(){
		$data = $this->getSampleHistogramData();
		$series = array();
		foreach ($this->getApiIds() as $index=>$apiId){
			$apiData = $this->getApiHistogramData($apiId);
			array_push($series, array('name' => $apiId, 'data' => array_values($apiData)));
		}
		$charOptions = array(
		  'theme' => 'gray',
	      'title' => array('text' => 'API执行性能(单位:微秒)'),
	      'xAxis' => array(
	         'categories' => array_keys($data)
		),
	      'yAxis' => array(
	         'title' => array('text' => '微秒')
		),
	      'series' => $series
		);
		return $charOptions;
	}
}